const express = require("express")
const pool = require("../utils/DBUtils")
var router = express.Router()

router.get("/list", async (req, res) => {
    let { result } = await pool.async.query("SELECT * from `zhsz_score`")
    res.send({
        msg: "查询成功",
        data: result
    })
})
// 添加接口
router.post("/add", async (req, res) => {
    let data = req.body
    let result =await pool.async.query("insert into zhsz_score(`stu_id`,`stu_name`,`sxzz`,`sxjk`,`ldsj`,`zyfw`) values(?,?,?,?,?,?)", [data.stu_id,data.stu_name,data.sxzz,data.sxjk,data.ldsj,data.zyfw])
    res.send({
        code: 200,
        msg: "添加成功",
        data: result
    })
})
//删除接口，根据id  删除数据
router.delete("/delete/:id",async(req,res)=>{
    let {id} = req.params
    let result = await pool.async.query("delete from zhsz_score where `stu_id`=?",[id])
    res.send({
        code:200,
        msg:"删除成功"
    })
})

//修改接口,根据id修改数据
router.put("/update",async(req,res)=>{
    let data = req.body
    let result = await pool.async.query("UPDATE zhsz_score SET sxzz=?,sxjk=?,ldsj=?,zyfw=? WHERE `stu_id`=?",[data.sxzz,data.sxjk,data.ldsj,data.zyfw,data.stu_id])  
    res.send({
        code: 200,
        msg: "修改成功",
        data: result
    })
})
module.exports = router